/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-11-20
 * 22:42
 */
public class Test {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @return ListNode类
     * **/
      public class ListNode {
        int val;
        ListNode next = null;
        public ListNode(int val) {
          this.val = val;
        }
      }

    public ListNode ReverseList (ListNode head) {
        // write code here
        if(head==null||head.next==null){//可以不用这个
            return head;
        }
        ListNode curPrev=null;//注意头节点翻转后要指向null；
        ListNode curN=head;
        while(curN!=null){
            ListNode cur=curN.next;
            curN.next=curPrev;
            curPrev=curN;
            curN=cur;
        }
        return curPrev;
    }
}